<template>
  <!-- 产业计划物资详情 -->
  <div class="sub-material-detail-comp page-container">
    <back-header></back-header>
    <div class="flex-auto overflow-y">
      <div class="page-container-inner full-height full-width no-scroll-x no-scroll-y flex-column">
        <data-detail :detailData="detailData"></data-detail>
      </div>
    </div>
  </div>
</template>

<script>
import BackHeader from '@/components/business/page-comp/back-header/back-header.vue';
import DataDetail from '@/components/business/page-comp/data-detail/data-detail.vue';
import api from '../api/index.js';
export default {
  name: 'SubMaterialDetail',
  components: { BackHeader, DataDetail },
  props: {
    subTaskId: {
      type: String,
      default() {
        return ''
      },
    },
  },
  data() {
    return {
      detailData: {}
    };
  },
  computed: {},
  beforeDestroy() { },
  created() {
    this.getDetail();
  },
  methods: {
    getDetail() {
      this.dataLoadig = true;
      api.getBusinessReviewSubTask({
        businessReviewSubTaskId: this.subTaskId
      })
        .then((res) => {
          this.dataLoadig = false;
          if (res.success) {
            this.$log.debug('查询产业计划子任务详情成功');
            this.buildDetail(res.data);
          } else {
            this.$log.error('查询产业计划子任务详情失败，错误信息为：', res.message);
            this.$message.error('查询产业计划子任务详情失败：' + (res.message || ''));
          }
        })
        .catch((e) => {
          this.dataLoadig = false;
          this.$log.error('查询产业计划子任务详情失败，错误信息为：', e);
        });
    },
    buildDetail(data = {}) {
      // 如下字段如果有值，则表示有字段需要告警
      const warnFildsList = [
        "planBachCodeResult",
        "planBachNameResult",
        "purchaseNumResult",
        "foundSourceResult",
        "projectSourceResult",
        "demandNameResult",
        "agreementUnitResult",
        "materialCodeResult",
        "demandQuantityResult",
        "quotationWayResult",
        "maxPriceResult",
        "estimatePriceResult",
        "estimatetotalResult",
        "deliveryAddressResult",
        "deliveryWayResult",
        "firstdeliveryDateResult",
        "lastdeliveryDateResult",
        "inviteUnitPhoneResult",
        "technicalspecificationsIdResult",
      ];
      const warnFields = [];
      const explains = [];
      warnFildsList.forEach(item => {
        if (data[item] && data[item].length) {
          warnFields.push(item.split('Result')[0]);
          explains.push(data[item]);
        }
      });
      this.detailData = {
        explains,
        data: [
          { label: '计划批次名称', span: 5, value: data.planBachName || '', warning: warnFields.indexOf('planBachName') !== -1 },
          { label: '工程项目名称', span: 5, value: data.projectName || '', warning: warnFields.indexOf('projectName') !== -1 },
          { label: '采购需求名称', span: 5, value: data.demandName || '', warning: warnFields.indexOf('demandName') !== -1 },

          { label: '计划批次编号', value: data.planBachCode || '', warning: warnFields.indexOf('planBachCode') !== -1 },
          { label: '审核状态', value: data.status || '', warning: warnFields.indexOf('status') !== -1 },
          { label: '大类描述', value: data.divisionDesc || '', warning: warnFields.indexOf('divisionDesc') !== -1 },

          { label: '工程项目编号', value: data.projectCode || '', warning: warnFields.indexOf('projectCode') !== -1 },
          { label: '工程项目来源', value: data.engineeringSource || '', warning: warnFields.indexOf('engineeringSource') !== -1 },
          { label: '中类描述', value: data.groupDesc || '', warning: warnFields.indexOf('groupDesc') !== -1 },

          { label: '技术规范书ID', value: data.technicalspecificationsId || '', warning: warnFields.indexOf('technicalspecificationsId') !== -1 },
          { label: '项目来源', value: data.projectSource || '', warning: warnFields.indexOf('projectSource') !== -1 },
          { label: '小类描述', value: data.classDesc || '', warning: warnFields.indexOf('classDesc') !== -1 },

          { label: '物料编码', value: data.materialCode || '', warning: warnFields.indexOf('materialCode') !== -1 },
          { label: '项目单位', value: data.projectUnit || '', warning: warnFields.indexOf('projectUnit') !== -1 },
          { label: '物料描述', value: data.materialDesc || '', warning: warnFields.indexOf('materialDesc') !== -1 },

          { label: '物料扩展编码', value: data.materialExtendCode || '', warning: warnFields.indexOf('materialExtendCode') !== -1 },
          { label: '合同签订单位', value: data.agreementUnit || '', warning: warnFields.indexOf('agreementUnit') !== -1 },
          { label: '物料长描述', value: data.materialLengthDesc || '', warning: warnFields.indexOf('materialLengthDesc') !== -1 },

          { label: '采购申请号', value: data.purchaseNum || '', warning: warnFields.indexOf('purchaseNum') !== -1 },
          { label: '拟邀请单位', value: data.inviteUnit || '', warning: warnFields.indexOf('inviteUnit') !== -1 },
          { label: '物料扩展描述', value: data.materialExtendDesc || '', warning: warnFields.indexOf('materialExtendDesc') !== -1 },

          { label: '计量单位', value: data.unit || '', warning: warnFields.indexOf('unit') !== -1 },
          { label: '拟邀请单位联系人电话', value: data.inviteUnitPhone || '', warning: warnFields.indexOf('inviteUnitPhone') !== -1 },
          { label: '归口单位', value: data.literallyUnit || '', warning: warnFields.indexOf('literallyUnit') !== -1 },

          { label: '报价方式', value: data.quotationWay || '', warning: warnFields.indexOf('quotationWay') !== -1 },
          { label: '概（预）算价（元）', value: data.estimatetotal || '', warning: warnFields.indexOf('estimatetotal') !== -1 },
          { label: '需求数量', value: data.demandQuantity || '', warning: warnFields.indexOf('demandQuantity') !== -1 },

          { label: '资金来源', value: data.foundSource || '', warning: warnFields.indexOf('foundSource') !== -1 },
          { label: '最高限价（元）', value: data.maxPrice || '', warning: warnFields.indexOf('maxPrice') !== -1 },
          { label: '首批交货期', value: data.firstdeliveryDate || '', warning: warnFields.indexOf('firstdeliveryDate') !== -1 },

          { label: '交货地点', value: data.deliveryAddress || '', warning: warnFields.indexOf('deliveryAddress') !== -1 },
          { label: '计划编制人', value: data.preparedBy || '', warning: warnFields.indexOf('preparedBy') !== -1 },
          { label: '最后一批交货期', value: data.lastdeliveryDate || '', warning: warnFields.indexOf('lastdeliveryDate') !== -1 },

          { label: '交货方式', value: data.deliveryWay || '', warning: warnFields.indexOf('deliveryWay') !== -1 },
          { label: '计划编制人手机号', value: data.phone || '', warning: warnFields.indexOf('phone') !== -1 },
          { label: '需求计划状态', value: data.planStatus || '', warning: warnFields.indexOf('planStatus') !== -1 },

          { label: '其他备注事项', span: 5, value: data.elseNote || '', warning: warnFields.indexOf('elseNote') !== -1 },

          { label: '历史退回原因', span: 5, value: data.returnRemark || '', warning: warnFields.indexOf('returnRemark') !== -1 },

        ]
      };
    },
  }
};
</script>

<style lang="scss" scoped>
.sub-material-detail-comp {}
</style>
